<!DOCTYPE html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.3" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.3">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.3" color="#222">





  <meta name="keywords" content="Java,远程调用,WebService," />










<meta name="description" content="一种跨编程语言和跨操作系统平台的远程调用技术规范。用来实现不同语言或系统之间的数据交互。 cxf 是WebService在Java语言中的一种实现框架。 按固定的格式来传递信息。 如果是Java调用Java？ ​    RMI(远程方法调用)：实现框架：hession 三规范Java中共有三种WebService规范：">
<meta name="keywords" content="Java,远程调用,WebService">
<meta property="og:type" content="article">
<meta property="og:title" content="WebService的使用">
<meta property="og:url" content="http://ivon.top/2017/08/08/WebService/index.html">
<meta property="og:site_name" content="Ivon&#39;s Notebook">
<meta property="og:description" content="一种跨编程语言和跨操作系统平台的远程调用技术规范。用来实现不同语言或系统之间的数据交互。 cxf 是WebService在Java语言中的一种实现框架。 按固定的格式来传递信息。 如果是Java调用Java？ ​    RMI(远程方法调用)：实现框架：hession 三规范Java中共有三种WebService规范：  JAX-WS(JAX-RPC) 全称 Java API for XML-Ba">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2017-11-27T10:59:26.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="WebService的使用">
<meta name="twitter:description" content="一种跨编程语言和跨操作系统平台的远程调用技术规范。用来实现不同语言或系统之间的数据交互。 cxf 是WebService在Java语言中的一种实现框架。 按固定的格式来传递信息。 如果是Java调用Java？ ​    RMI(远程方法调用)：实现框架：hession 三规范Java中共有三种WebService规范：  JAX-WS(JAX-RPC) 全称 Java API for XML-Ba">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '5.1.3',
    sidebar: {"position":"left","display":"always","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":true,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: 'UVBQP5J09B',
      apiKey: 'c52c00bfaff064f97caf9a6c225af449',
      indexName: 'ivon',
      hits: {"per_page":10},
      labels: {"input_placeholder":"~请输入需要查询的内容~","hits_empty":"然而查询 ${query} 并没有找到结果~","hits_stats":"找到了 ${hits} 个结果，耗时 ${time} ms~"}
    }
  };
</script>



  <link rel="canonical" href="http://ivon.top/2017/08/08/WebService/"/>





  <title>WebService的使用 | Ivon's Notebook</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Ivon's Notebook</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <h1 class="site-subtitle" itemprop="description"></h1>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  
  <div class="algolia-popup popup search-popup">
    <div class="algolia-search">
      <div class="algolia-search-input-icon">
        <i class="fa fa-search"></i>
      </div>
      <div class="algolia-search-input" id="algolia-search-input"></div>
    </div>

    <div class="algolia-results">
      <div id="algolia-stats"></div>
      <div id="algolia-hits"></div>
      <div id="algolia-pagination" class="algolia-pagination"></div>
    </div>

    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
  </div>




    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://ivon.top/2017/08/08/WebService/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Ivon Ma">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Ivon's Notebook">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">WebService的使用</h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-08-08T10:14:16+08:00">
                2017-08-08
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/后端/" itemprop="url" rel="index">
                    <span itemprop="name">后端</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2017/08/08/WebService/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count gitment-comments-count" data-xid="/2017/08/08/WebService/" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o"></i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>
            </span>
          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>一种<strong>跨编程语言</strong>和<strong>跨操作系统平台</strong>的远程调用技术规范。用来实现不同语言或系统之间的数据交互。</p>
<p>cxf 是WebService在Java语言中的一种实现框架。</p>
<p>按固定的格式来传递信息。</p>
<p>如果是Java调用Java？</p>
<p>​    RMI(远程方法调用)：实现框架：hession</p>
<h2 id="三规范"><a href="#三规范" class="headerlink" title="三规范"></a>三规范</h2><p>Java中共有三种WebService规范：</p>
<ol>
<li><p>JAX-WS(JAX-RPC)</p>
<p>全称 Java API for XML-Based WebService</p>
<ul>
<li>开发简单，高度封装实现细节</li>
<li>比较笨重，需要导入大量 Jar</li>
<li>目前已经被 JAX-RS 取代，大多是传统项目在用</li>
</ul>
</li>
<li><p>JAXM&amp;SAAJ</p>
<p>Java API For XML Message</p>
<ul>
<li>暴露了更多的SOAP底层细节，编码比较麻烦</li>
</ul>
</li>
<li><p>JAX-RS</p>
<p>Java针对REST(Representation State Transfer) 风格制定的一套Web服务规范。</p>
<ul>
<li>比较新，08年才有了具体的实现，随JDK1.7发布</li>
<li>目前电商系统更多采用</li>
</ul>
</li>
</ol>
<h2 id="三要素"><a href="#三要素" class="headerlink" title="三要素"></a>三要素</h2><h3 id="1-SOAP"><a href="#1-SOAP" class="headerlink" title="1.SOAP"></a>1.SOAP</h3><p>soap协议是WebService的传输协议，即简单对象访问协议。<br>Soap协议是xml格式，<strong>基于http传输xml数据</strong>。</p>
<p>特点：跨平台，跨语言，w3c指定</p>
<h3 id="2-WSDL"><a href="#2-WSDL" class="headerlink" title="2.WSDL"></a>2.WSDL</h3><p>WebService 的使用说明书。<br>Web Service Description Language 网络服务描述语言，是一种使用XML编写的文档，用于描述或定位网络服务。</p>
<p>例如，其中描述了接口提供的方法的方法名，参数和返回值等</p>
<h3 id="3-UDDI"><a href="#3-UDDI" class="headerlink" title="3.UDDI"></a>3.UDDI</h3><p>统一描述、发现和集成协议<br>是一个目录服务，存储了全球的WebService地址。</p>
<h1 id="CXF-框架"><a href="#CXF-框架" class="headerlink" title="CXF 框架"></a>CXF 框架</h1><h3 id="简介"><a href="#简介" class="headerlink" title="简介"></a>简介</h3><h5 id="什么是CXF"><a href="#什么是CXF" class="headerlink" title="什么是CXF"></a>什么是CXF</h5><p>Celtix + Xfire<br>是一个Java下的开源WebService框架。<br>支持多种协议，比如：SOAP1.1, 1.2, XML/HTTP, REST HTTP, CORBA<br>以下使用的是JAX-WS，但CXF也支持JAX-RS。</p>
<h5 id="jar包-Maven坐标"><a href="#jar包-Maven坐标" class="headerlink" title="jar包/Maven坐标"></a>jar包/Maven坐标</h5><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- https://mvnrepository.com/artifact/org.apache.cxf/cxf-rt-frontend-jaxws --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.apache.cxf<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>cxf-rt-frontend-jaxws<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>3.0.2<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="comment">&lt;!-- https://mvnrepository.com/artifact/org.apache.cxf/cxf-rt-transports-http-jetty --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.apache.cxf<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>cxf-rt-transports-http-jetty<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>3.0.2<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h5 id="安装目录构成："><a href="#安装目录构成：" class="headerlink" title="安装目录构成："></a>安装目录构成：</h5><p>bin: 可执行命令</p>
<p>docs:文档</p>
<p>etc:杂项</p>
<p>lib:jar包</p>
<p>samples:案例</p>
<h2 id="服务器端开发步骤："><a href="#服务器端开发步骤：" class="headerlink" title="服务器端开发步骤："></a>服务器端开发步骤：</h2><ol>
<li><p>导入Jar包</p>
</li>
<li><p>创建服务类及接口，添加供远程调用的方法</p>
<ul>
<li>接口必须有<strong>@WebService</strong>注解</li>
<li>实现类的方法必须有<strong>@WebMethod</strong>注解</li>
</ul>
</li>
<li><p>发布WebService：</p>
<h5 id="非Spring整合方式发布"><a href="#非Spring整合方式发布" class="headerlink" title="非Spring整合方式发布"></a>非Spring整合方式发布</h5></li>
<li><p>创建生产服务的工厂类</p>
<p><code>JaxWsServerFactoryBean factoryBean = newJaxWsServerFactoryBean ();</code></p>
</li>
<li><p>设置访问地址（提供给外界访问本服务的地址）</p>
<p><code>factoryBean.setAddress(&quot;http://localhost:12345/weather&quot;&quot;);</code></p>
</li>
<li><p>设置具体服务对象</p>
<p><code>factoryBean.setServiceBean(new WeatherService());</code></p>
</li>
<li><p>创建服务</p>
<p><code>factoryBean.create();</code></p>
</li>
</ol>
<h5 id="Spring整合方式发布："><a href="#Spring整合方式发布：" class="headerlink" title="Spring整合方式发布："></a>Spring整合方式发布：</h5><ol>
<li><p>Spring配置文件中配置<jaxws:server></jaxws:server></p>
<ul>
<li><p>address属性定义的是服务的路径，即?wsdl前面那个路径。注意其与项目路径和CXFServlet的url-pattern的区别：</p>
<p>假设项目路径为ivon，web.xml中CXFServlet的url-pattern为ws，此处address为/weather，则最后访问wsdl的路径为：<code>http://localhost:8081/ivon/ws/weather?wsdl</code></p>
</li>
</ul>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span><br><span class="line"><span class="tag">&lt;<span class="name">beans</span> <span class="attr">xmlns</span>=<span class="string">"http://www.springframework.org/schema/beans"</span></span></span><br><span class="line"><span class="tag">    <span class="attr">xmlns:xsi</span>=<span class="string">"http://www.w3.org/2001/XMLSchema-instance"</span></span></span><br><span class="line"><span class="tag">    <span class="attr">xmlns:cxf</span>=<span class="string">"http://cxf.apache.org/core"</span></span></span><br><span class="line"><span class="tag">    <span class="attr">xmlns:jaxws</span>=<span class="string">"http://cxf.apache.org/jaxws"</span></span></span><br><span class="line"><span class="tag">    <span class="attr">xmlns:jaxrs</span>=<span class="string">"http://cxf.apache.org/jaxrs"</span></span></span><br><span class="line"><span class="tag">    <span class="attr">xsi:schemaLocation</span>=<span class="string">"</span></span></span><br><span class="line"><span class="tag"><span class="string">        http://www.springframework.org/schema/beans </span></span></span><br><span class="line"><span class="tag"><span class="string">        http://www.springframework.org/schema/beans/spring-beans.xsd</span></span></span><br><span class="line"><span class="tag"><span class="string">        http://cxf.apache.org/core</span></span></span><br><span class="line"><span class="tag"><span class="string">        http://cxf.apache.org/schemas/core.xsd</span></span></span><br><span class="line"><span class="tag"><span class="string">        http://cxf.apache.org/jaxws</span></span></span><br><span class="line"><span class="tag"><span class="string">        http://cxf.apache.org/schemas/jaxws.xsd</span></span></span><br><span class="line"><span class="tag"><span class="string">        http://cxf.apache.org/jaxrs</span></span></span><br><span class="line"><span class="tag"><span class="string">        http://cxf.apache.org/schemas/jaxrs.xsd"</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!-- 创建服务bean --&gt;</span>    </span><br><span class="line">	<span class="tag">&lt;<span class="name">bean</span> <span class="attr">id</span>=<span class="string">"serviceBean"</span> <span class="attr">class</span>=<span class="string">"cn.itcast.jx.webservice.WeatherService"</span>&gt;</span><span class="tag">&lt;/<span class="name">bean</span>&gt;</span>	</span><br><span class="line">	</span><br><span class="line">	<span class="comment">&lt;!-- 发布服务 --&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">jaxws:server</span> <span class="attr">address</span>=<span class="string">"/weather"</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">jaxws:serviceBean</span>&gt;</span></span><br><span class="line">			<span class="comment">&lt;!-- 配置服务bean --&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">ref</span> <span class="attr">bean</span>=<span class="string">"serviceBean"</span>/&gt;</span></span><br><span class="line">		<span class="tag">&lt;/<span class="name">jaxws:serviceBean</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">jaxws:server</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">beans</span>&gt;</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>web.xml 配置 CXF的核心控制器<strong>CXFServlet</strong></p>
<ul>
<li><p>特别注意url-pattern最后要加通配符：  /xx/* 这是由于客户端对其的访问必然会在Servlet的url后拼接？？？</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span><br><span class="line"><span class="tag">&lt;<span class="name">web-app</span> <span class="attr">xmlns:xsi</span>=<span class="string">"http://www.w3.org/2001/XMLSchema-instance"</span> <span class="attr">xmlns</span>=<span class="string">"http://java.sun.com/xml/ns/javaee"</span> <span class="attr">xsi:schemaLocation</span>=<span class="string">"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"</span> <span class="attr">id</span>=<span class="string">"WebApp_ID"</span> <span class="attr">version</span>=<span class="string">"2.5"</span>&gt;</span></span><br><span class="line">  <span class="comment">&lt;!-- 加载spring配置文件 --&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">listener</span>&gt;</span></span><br><span class="line">       <span class="tag">&lt;<span class="name">listener-class</span>&gt;</span>org.springframework.web.context.ContextLoaderListener<span class="tag">&lt;/<span class="name">listener-class</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">listener</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">context-param</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">param-name</span>&gt;</span>contextConfigLocation<span class="tag">&lt;/<span class="name">param-name</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">param-value</span>&gt;</span>classpath:applicationContext.xml<span class="tag">&lt;/<span class="name">param-value</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">context-param</span>&gt;</span></span><br><span class="line">  </span><br><span class="line">  <span class="comment">&lt;!-- CXF的核心控制器 --&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">servlet</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">servlet-name</span>&gt;</span>cxf<span class="tag">&lt;/<span class="name">servlet-name</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">servlet-class</span>&gt;</span>org.apache.cxf.transport.servlet.CXFServlet<span class="tag">&lt;/<span class="name">servlet-class</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">servlet</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">servlet-mapping</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">servlet-name</span>&gt;</span>cxf<span class="tag">&lt;/<span class="name">servlet-name</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">url-pattern</span>&gt;</span>/ws/*<span class="tag">&lt;/<span class="name">url-pattern</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">servlet-mapping</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">web-app</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>​</p>
</li>
</ul>
</li>
</ol>
<h6 id="测试服务器端是否正常："><a href="#测试服务器端是否正常：" class="headerlink" title="测试服务器端是否正常："></a>测试服务器端是否正常：</h6><p>​    访问wsdl地址，即服务器提供的访问地址后拼接?wsdl，如 localhost:12345/weather?wsdl。如果服务器端的设置有问题，一般打开的页面只会有几行或十几行。</p>
<h2 id="客户端开发步骤："><a href="#客户端开发步骤：" class="headerlink" title="客户端开发步骤："></a>客户端开发步骤：</h2><ol>
<li><p>添加Jar包</p>
</li>
<li><p>利用wsimport生成本地代码</p>
<p>简介：wsimport是JDK提供的一个工具，用于将wsdl说明书翻译成Java代码</p>
<p>位置：JDK安装目录的bin目录下</p>
<p>使用方式：切换到要生成客户端代码的src目录，运行wsimport命令，自动生成客户端代码</p>
<p>wsimport命令<code>wsimport -s . http://localhost:12345/weather?wsdl</code></p>
<p>​    其中-s表示将代码生成到指定目录</p>
<p>​    .表示当前目录</p>
</li>
<li><p>在需要的位置，调用本地代码</p>
<h5 id="非Spring整合方式："><a href="#非Spring整合方式：" class="headerlink" title="非Spring整合方式："></a>非Spring整合方式：</h5></li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//1. 创建客户端代理对象</span></span><br><span class="line">JaxWsProxyFactoryBean proxy = <span class="keyword">new</span> JaxWsProxyFactoryBean();</span><br><span class="line"><span class="comment">//2. 设置服务接口</span></span><br><span class="line">proxy.setServiceClass(IWeatherService.class);</span><br><span class="line"><span class="comment">//3. 设置访问地址：wsdl使用说明书的地址</span></span><br><span class="line">proxy.setAddress(<span class="string">"http://localhost:12345/weather?wsdl"</span>);</span><br><span class="line"><span class="comment">//4.创建服务对象</span></span><br><span class="line">IWeatherService iws = (IWeatherService) proxy.create();</span><br><span class="line"><span class="comment">//5.调用方法</span></span><br><span class="line">String result = iws.getWeatherByCityName(<span class="string">"北京"</span>);<span class="comment">//调用的其实是服务端的方法（也可称为远程方法调用 ）</span></span><br></pre></td></tr></table></figure>
<h5 id="Spring方式："><a href="#Spring方式：" class="headerlink" title="Spring方式："></a>Spring方式：</h5><p>​    1. applicationContext.xml 配置<jaxws:client> </jaxws:client></p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span><br><span class="line"><span class="tag">&lt;<span class="name">beans</span> <span class="attr">xmlns</span>=<span class="string">"http://www.springframework.org/schema/beans"</span></span></span><br><span class="line"><span class="tag">    <span class="attr">xmlns:xsi</span>=<span class="string">"http://www.w3.org/2001/XMLSchema-instance"</span></span></span><br><span class="line"><span class="tag">    <span class="attr">xmlns:cxf</span>=<span class="string">"http://cxf.apache.org/core"</span></span></span><br><span class="line"><span class="tag">    <span class="attr">xmlns:jaxws</span>=<span class="string">"http://cxf.apache.org/jaxws"</span></span></span><br><span class="line"><span class="tag">    <span class="attr">xmlns:jaxrs</span>=<span class="string">"http://cxf.apache.org/jaxrs"</span></span></span><br><span class="line"><span class="tag">    <span class="attr">xsi:schemaLocation</span>=<span class="string">"</span></span></span><br><span class="line"><span class="tag"><span class="string">        http://www.springframework.org/schema/beans </span></span></span><br><span class="line"><span class="tag"><span class="string">        http://www.springframework.org/schema/beans/spring-beans.xsd</span></span></span><br><span class="line"><span class="tag"><span class="string">        http://cxf.apache.org/core</span></span></span><br><span class="line"><span class="tag"><span class="string">        http://cxf.apache.org/schemas/core.xsd</span></span></span><br><span class="line"><span class="tag"><span class="string">        http://cxf.apache.org/jaxws</span></span></span><br><span class="line"><span class="tag"><span class="string">        http://cxf.apache.org/schemas/jaxws.xsd</span></span></span><br><span class="line"><span class="tag"><span class="string">        http://cxf.apache.org/jaxrs</span></span></span><br><span class="line"><span class="tag"><span class="string">        http://cxf.apache.org/schemas/jaxrs.xsd"</span>&gt;</span></span><br><span class="line">         <span class="comment">&lt;!-- id:当前标签的唯一标识</span></span><br><span class="line"><span class="comment">              address：wsdl使用说明书的地址</span></span><br><span class="line"><span class="comment">              serviceClass:接口</span></span><br><span class="line"><span class="comment">         --&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">jaxws:client</span> <span class="attr">id</span>=<span class="string">"serviceBean"</span> <span class="attr">address</span>=<span class="string">"http://localhost:8090/wsCXFSpringServer/ws/weather?wsdl"</span> </span></span><br><span class="line"><span class="tag">	    <span class="attr">serviceClass</span>=<span class="string">"cn.itcast.jx.webservice.IWeatherService"</span> </span></span><br><span class="line"><span class="tag">    &gt;</span><span class="tag">&lt;/<span class="name">jaxws:client</span>&gt;</span></span><br><span class="line">	</span><br><span class="line"><span class="tag">&lt;/<span class="name">beans</span>&gt;</span></span><br></pre></td></tr></table></figure>
<ol>
<li><p>调用方法</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">test01</span><span class="params">()</span></span>&#123;</span><br><span class="line">  <span class="comment">//加载配置文件</span></span><br><span class="line">    ApplicationContext ctx = <span class="keyword">new</span> ClassPathXmlApplicationContext(<span class="string">"classpath:applicationContext.xml"</span>);</span><br><span class="line">    IWeatherService service = (IWeatherService) ctx.getBean(<span class="string">"serviceBean"</span>);</span><br><span class="line">    String result = service.getWeatherByCityName(<span class="string">"北京"</span>);</span><br><span class="line">	System.out.println(result);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>​</p>
</li>
</ol>
<h2 id="其他注意事项："><a href="#其他注意事项：" class="headerlink" title="其他注意事项："></a>其他注意事项：</h2><ul>
<li>客户端请求服务器，服务器必须在<strong>90</strong>秒内做出响应，否则客户端会报错“服务端没有响应”。这种情况容易出现在debug时。</li>
<li>与Spring整合时，配置文件建议单独写一个，在主配置文件中引入</li>
</ul>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>Would you plz spare me a cup of coffee?</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechatpay.jpg" alt="Ivon Ma 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.jpg" alt="Ivon Ma 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Java/" rel="tag"># Java</a>
          
            <a href="/tags/远程调用/" rel="tag"># 远程调用</a>
          
            <a href="/tags/WebService/" rel="tag"># WebService</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/08/04/Quartz 实现定时任务调度/" rel="next" title="Quartz实现定时任务调度">
                <i class="fa fa-chevron-left"></i> Quartz实现定时任务调度
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/08/15/jQuery插件/" rel="prev" title="jQuery插件">
                jQuery插件 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      
        <div id="gitment-container"></div>
      
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/avatar.jpg"
                alt="Ivon Ma" />
            
              <p class="site-author-name" itemprop="name">Ivon Ma</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">18</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">5</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">34</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          <div class="links-of-author motion-element">
            
              
                <span class="links-of-author-item">
                  <a href="https://github.com/IvonMa" target="_blank" title="GitHub">
                    
                      <i class="fa fa-fw fa-github"></i>GitHub</a>
                </span>
              
                <span class="links-of-author-item">
                  <a href="https://www.zhihu.com/people/ma-yun-feng/" target="_blank" title="Zhihu">
                    
                      <i class="fa fa-fw fa-heart-o"></i>Zhihu</a>
                </span>
              
                <span class="links-of-author-item">
                  <a href="mailto:ivonma@126.com" target="_blank" title="E-Mail">
                    
                      <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                </span>
              
            
          </div>

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#三规范"><span class="nav-number">1.</span> <span class="nav-text">三规范</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#三要素"><span class="nav-number">2.</span> <span class="nav-text">三要素</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-SOAP"><span class="nav-number">2.1.</span> <span class="nav-text">1.SOAP</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-WSDL"><span class="nav-number">2.2.</span> <span class="nav-text">2.WSDL</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-UDDI"><span class="nav-number">2.3.</span> <span class="nav-text">3.UDDI</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#CXF-框架"><span class="nav-number"></span> <span class="nav-text">CXF 框架</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#简介"><span class="nav-number">0.1.</span> <span class="nav-text">简介</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#什么是CXF"><span class="nav-number">0.1.0.1.</span> <span class="nav-text">什么是CXF</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#jar包-Maven坐标"><span class="nav-number">0.1.0.2.</span> <span class="nav-text">jar包/Maven坐标</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#安装目录构成："><span class="nav-number">0.1.0.3.</span> <span class="nav-text">安装目录构成：</span></a></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#服务器端开发步骤："><span class="nav-number">1.</span> <span class="nav-text">服务器端开发步骤：</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#非Spring整合方式发布"><span class="nav-number">1.0.0.1.</span> <span class="nav-text">非Spring整合方式发布</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#Spring整合方式发布："><span class="nav-number">1.0.0.2.</span> <span class="nav-text">Spring整合方式发布：</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#测试服务器端是否正常："><span class="nav-number">1.0.0.2.1.</span> <span class="nav-text">测试服务器端是否正常：</span></a></li></ol></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#客户端开发步骤："><span class="nav-number">2.</span> <span class="nav-text">客户端开发步骤：</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#非Spring整合方式："><span class="nav-number">2.0.0.1.</span> <span class="nav-text">非Spring整合方式：</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#Spring方式："><span class="nav-number">2.0.0.2.</span> <span class="nav-text">Spring方式：</span></a></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#其他注意事项："><span class="nav-number">3.</span> <span class="nav-text">其他注意事项：</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2013 &mdash; <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Ivon Ma</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Mist</a> v5.1.3</div>




        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.3"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.3"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.3"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.3"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.3"></script>



  


  




	





  





  







<!-- LOCAL: You can save these files to your site and update links -->
    
        
        <link rel="stylesheet" href="https://aimingoo.github.io/gitmint/style/default.css">
        <script src="https://aimingoo.github.io/gitmint/dist/gitmint.browser.js"></script>
    
<!-- END LOCAL -->

    
      <style>
        a.gitment-editor-footer-tip { display: none; }
        .gitment-container.gitment-footer-container { display: none; }
      </style>
    

    
      <script type="text/javascript">
      function renderGitment(){
        var gitment = new Gitmint({
            id: window.location.pathname, 
            owner: 'IvonMa',
            repo: 'ivonma.github.io',
            
            lang: "" || navigator.language || navigator.systemLanguage || navigator.userLanguage,
            
            oauth: {
            
            
                client_secret: 'd61c00dc8d0f99d82c36e47096dedf79a1f47cb6',
            
                client_id: 'ac63a706f554739bbcaa'
            }});
        gitment.render('gitment-container');
      }

      
      renderGitment();
      
      </script>
    







  




  
  
  
  <link rel="stylesheet" href="/lib/algolia-instant-search/instantsearch.min.css">

  
  
  <script src="/lib/algolia-instant-search/instantsearch.min.js"></script>
  

  <script src="/js/src/algolia-search.js?v=5.1.3"></script>



  

  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  
  
  
  <link rel="stylesheet" href="/lib/needsharebutton/needsharebutton.css">

  
  
  <script src="/lib/needsharebutton/needsharebutton.js"></script>

  <script>
    
    
  </script>

  

  

  

  

</body>
</html>
